package v3.chapter2.t3;

public class Run {

	public static void main(String[] args) {
		try {
			PublicVar publicVarRef=new PublicVar();
			ThreadA thread=new ThreadA(publicVarRef);
			thread.start();
			Thread.sleep(200);
			publicVarRef.getValue();
		}catch(InterruptedException e) {
			e.printStackTrace();
		}

	}

}

class ThreadA extends Thread{
	private PublicVar publicVar;
	public ThreadA(PublicVar publicVar) {
		super();
		this.publicVar=publicVar;
	}
	
	public void run() {
		super.run();
		publicVar.setValue("B", "BB");
	}
}


class PublicVar{
	public String username="A";
	public String password="AA";
	
	 synchronized public void setValue(String username,String password) {
		try {
			this.username=username;
			Thread.sleep(5000);
			this.password=password;
			System.out.println("setValue method thread name="+Thread.currentThread().getName()+" username="+username+" password="+password);
		}catch(InterruptedException e) {
			e.printStackTrace();
		}
	}
	//public void getValue() {
	 synchronized public void getValue() {
		 System.out.println("setValue method thread name="+Thread.currentThread().getName()+" username="+username+" password="+password);
	 }
}